package com.easyattendance.services;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ValidationsService {

	public String validateName(String name) {
		if(name.length()==0){
			return "Name cannot be blank.";
		}
		
		if(name.length()<2 || name.length()>32) {
			return "Length of name must be from 2 to 32 characters.";
		}
		
		// check whether name is alpha numeric or not
		return "Correct";
		
	}
	
	public String validateEmailId(String emailId) {
		String emailPattern="^([A-Za-z0-9_\\-\\.])+\\@([A-Za-z0-9_\\-\\.])+\\.([A-Za-z]{2,4})";
		
		if(emailId.length()==0 || emailId.length()>50){
			return "Email-id cannot be blank. Maximum 50 characters";
		}		
		if( emailId.matches(emailPattern)){
			return "Correct";
		}
		else {
			return "Invalid email-id";
		}
	}
	
	public boolean validateBothPasswords(String password, String repassword) {
		if( !password.equals(repassword)){
			return false;
		}
		else {
			return true;
		}
	}

	public String validatePassword(String password) {
		String passPattern = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{8,32})";
		Pattern p = Pattern.compile(passPattern);
		Matcher m = p.matcher(password);
		
		if(password.length()==0 || password.length()<8 || password.length()>32){
			return "Minimum 8 & maximum 32 characters";
		}
		if( m.matches()){
			return "Correct";
		}
		else {
			return "Invalid password.At least 1 Capital, 1 Special character, 1 Digit.";
		}
	}
}
